<?php

namespace App\Http\Controllers;

use App\Enum\Http\ApiCode;
use Illuminate\Http\JsonResponse;

abstract class Controller
{
    protected function error($msg = 'error', $data = [], ApiCode $code = ApiCode::Error): JsonResponse
    {
        return $this->apiJson($code, $msg, $data);
    }

    protected function success($data = [], $msg = 'success', ApiCode $code = ApiCode::Success): JsonResponse
    {
        return $this->apiJson($code, $msg, $data);
    }

    protected function apiJson(ApiCode $code, $msg, $data): JsonResponse
    {
        return response()->json([
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ]);
    }
}
